package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DzKsfxMapper;
import com.ruoyi.system.domain.DzKsfx;
import com.ruoyi.system.service.IDzKsfxService;


import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.mapper.DzHuiyuanMapper;
import com.ruoyi.system.domain.DzHuiyuan;
import com.ruoyi.system.service.IDzHuiyuanService;

/**
 * 考试分析Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-10-09
 */
@Service
public class DzKsfxServiceImpl implements IDzKsfxService 
{
    @Autowired
    private DzKsfxMapper dzKsfxMapper;

    @Autowired
    private ISysRoleService sysRoleService;

    @Autowired
    private IDzHuiyuanService dzHuiyuanService;

    /**
     * 查询考试分析
     * 
     * @param fxId 考试分析主键
     * @return 考试分析
     */
    @Override
    public DzKsfx selectDzKsfxByFxId(Long fxId)
    {
        return dzKsfxMapper.selectDzKsfxByFxId(fxId);
    }

    /**
     * 查询考试分析列表
     * 
     * @param dzKsfx 考试分析
     * @return 考试分析
     */
    @Override
    public List<DzKsfx> selectDzKsfxList(DzKsfx dzKsfx)
    {

        //权限控制
        SysUser user=  SecurityUtils.getLoginUser().getUser();
        List<SysRole> listRole= sysRoleService.selectRolesByUserId(user.getUserId());
        int datascope = 5;
        for(SysRole role:listRole){
            if( role.getDataScope()!=null&&Integer.parseInt(role.getDataScope())<datascope){
                datascope=Integer.parseInt(role.getDataScope());
            }
        }
        dzKsfx.setDatascope(datascope);
        if(datascope==4){
            dzKsfx.setCheckDeptId(user.getDeptId());
        }
        if(datascope==5){
            DzHuiyuan huiyuan =  dzHuiyuanService.selectDzHuiyuanByDn(user.getPhonenumber());
            if(huiyuan!=null){
                dzKsfx.setCheckHuiyuanId(huiyuan.getId());
            }else{
                dzKsfx.setCheckHuiyuanId(0l);
            }

        }
        return dzKsfxMapper.selectDzKsfxList(dzKsfx);
    }

    @Override
    public List<DzKsfx> selectDzKsfxListWeb(DzKsfx dzKsfx)
    {
        return dzKsfxMapper.selectDzKsfxList(dzKsfx);
    }

    /**
     * 新增考试分析
     * 
     * @param dzKsfx 考试分析
     * @return 结果
     */
    @Override
    public int insertDzKsfx(DzKsfx dzKsfx)
    {
        return dzKsfxMapper.insertDzKsfx(dzKsfx);
    }

    /**
     * 修改考试分析
     * 
     * @param dzKsfx 考试分析
     * @return 结果
     */
    @Override
    public int updateDzKsfx(DzKsfx dzKsfx)
    {
        return dzKsfxMapper.updateDzKsfx(dzKsfx);
    }

    /**
     * 批量删除考试分析
     * 
     * @param fxIds 需要删除的考试分析主键
     * @return 结果
     */
    @Override
    public int deleteDzKsfxByFxIds(Long[] fxIds)
    {
        return dzKsfxMapper.deleteDzKsfxByFxIds(fxIds);
    }

    /**
     * 删除考试分析信息
     * 
     * @param fxId 考试分析主键
     * @return 结果
     */
    @Override
    public int deleteDzKsfxByFxId(Long fxId)
    {
        return dzKsfxMapper.deleteDzKsfxByFxId(fxId);
    }
}
